package jdk8特性_壹证通公司面试.流;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

/**
 * Created by hongcaixia on 2019/10/31.
 */
public class MyStream1 {

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("陈奕迅");
        list.add("陈小春");
        list.add("钟汉良");
        list.add("陈七");
        list.add("陈伟霆");
        //筛选陈开头，名字是三个字的
        List<String> chenList = new ArrayList<>();
        for(String item : list){
            if(item.startsWith("陈")){
                chenList.add(item);
            }
        }

        List<String> threeList = new ArrayList<>();
        for(String item : chenList){
            if(item.length()==3){
                threeList.add(item);
            }
        }

        //遍历输出符合条件的
        for(String item : threeList){
            System.out.println(item);
        }

        System.out.println("=====================");

        //使用Stream流
        list.stream()
                .filter(str->str.startsWith("陈"))
                .filter(str->str.length()==3)
                .forEach(str-> System.out.println(str));
//----------------------
        /*ArrayList<Integer> list1 = new ArrayList<>();
        list1.add(1);
        list1.add(2);
        list1.add(3);
        Stream<Integer> stream = list1.stream();
        long count = stream.count();
        System.out.println(count);*/
//-----------------------
        Integer[] nums = {2,9,0,5,-10,90};
        Stream<Integer> numsStream = Stream.of(nums);
        Stream<Integer> sortedStram = numsStream.sorted();
        sortedStram.forEach(num -> System.out.println(num));
    }
}
